﻿using Autofac.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CommonHelper.AutofacCommon
{
    public class AutowiredPropertySelector : IPropertySelector
    {
        /// <summary>
        /// 查看属性上是否标记某一个特性
        /// </summary>
        /// <param name="propertyInfo"></param>
        /// <param name="instance"></param>
        /// <returns></returns>
        public bool InjectProperty(PropertyInfo propertyInfo, object instance)
        {
            //判断属性的特性是否包含自定义的属性,标记有返回true
            // return pi.GetCustomAttributes(typeof(AutowiredPropertyAttribute), false).Length > 0;
            return propertyInfo.CustomAttributes.Any(s => s.AttributeType == typeof(AutowiredPropertyAttribute));        
        }
    }
}
